package library.operation;

import library.Book;
import library.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation {
    @Override
    public void work(BookList booklist) {
        System.out.println("借书");
        Scanner scanner = new Scanner(System.in);
        //需要让用户输入要借的书的编号
        System.out.println("请输入要借阅的书的编号：");
        int id = scanner.nextInt();
        if (id < 0 || id >= booklist.getSize()){
            System.out.println("输入的编号不存在");
            return;
        }
        //修改书对应的状态就可以了
        Book book = booklist.getBook(id);
        if (book.isBorrowed()){
            System.out.println("该书已经被借走了");
            return;
        }
        //此时就把图书的借阅状态修改为ture
        book.setBorrowed(true);
        System.out.println("借阅成功");
    }
}
